class Solution:
    def deleteDuplicates(self, head: ListNode) -> ListNode:
        dummy = ListNode(0)
        dummy.next = head
        pre = dummy
        cur = head

        while cur and cur.next:
            if cur.val == cur.next.val:
                x = cur.val
                while cur and cur.val == x:
                    cur = cur.next
                pre.next = cur
            else:
                pre = cur
                cur = cur.next
        return dummy.next